package com.example.medicine.Mapper;




import com.example.medicine.Bean.book;
import com.example.medicine.Bean.yonghu;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface yonghuMapper  {
    @Select("select * from [yonghu] where userid=#{userid}")
    yonghu getById(String userid);
    /**
     * 得到全部的用户信息
     * @return
     */
    @Select("select * from [yonghu]")
    List<yonghu> getAll();

    @Select("SELECT DISTINCT LEFT(userid, 4)" +
            "FROM [yonghu]" +
            "WHERE LEN(userid) = 11;")
    List<String> getUserIdFour();

    @Select("select DISTINCT company from [yonghu]")
    List<String> getCompany();
    /**
     * 根据用户ID得到密码，密码为加密后的密码
     * @param userid
     * @return
     */
    @Select("select password from [yonghu] where userid=#{userid} ")
    yonghu getPasswordByUserid(@Param("userid")String userid);

    /**
     * 用户注册使用
     * @param yonghu
     */
    @Insert("insert into [yonghu](userid,username,password,image,type,tel,email,company,addr) values(#{userid},#{username},#{password},#{image},#{type},#{tel},#{email},#{company},#{addr})")
    void insert(yonghu yonghu);
    /**
     * 用户创建使用
     * @param yonghu
     */
    @Insert("insert into [yonghu](userid,username,password,image,type,tel,email,company,addr,createuser,createtime,teamName,teamID) " +
            "values(#{userid},#{username},#{password},#{image},#{type},#{tel},#{email},#{company},#{addr},#{createuser},#{createtime},#{teamName},#{teamID})")
    void insert2(yonghu yonghu);

    /**
     * 更新user表，根据主键（ID）
     * 团队名称，医生姓名，电话
     * @param yonghu
     */
    @Update("update [yonghu] set username=#{username},password=#{password},type=#{type},teamName=#{teamName},tel=#{tel},email=#{email},company=#{company},addr=#{addr} where userid=#{userid}")
    void update(yonghu yonghu);

    @Insert("<script>INSERT INTO [yonghu] (userid,username,password,type,tel,email,company,addr,createuser,createtime,teamName,teamID) VALUES " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.userid},#{item.username},#{item.password},#{item.type},#{item.tel},#{item.email},#{item.company},#{item.addr},#{item.createuser},getdate(),#{item.teamName},#{item.teamID})" +
            "</foreach></script>")
    void batchInsertUser(@Param("list") List<yonghu> user);

    @Update("update [yonghu] set image=#{image} where userid=#{userid}")
    void updateImage(yonghu yonghu);
    @Update("update [yonghu] set password=#{password} where userid=#{userid}")
    void updatepassword(yonghu yonghu);

    @Delete("delete from [yonghu] where userid=#{userid}")
    void deleteById(String userid);


}
